<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" href="${path}/static/layui/css/layui.css" media="all">
</head>
<body>
	<form class="layui-form layui-form-pane" id="update_form"  method="post" onsubmit="return false">
	
	  <input type="hidden" class="layui-input" name="id" value="${student.id}" /> 
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">姓名</label>
	    <div class="layui-input-inline">
	      <input name="name" class="layui-input" type="text" value="${student.name}" autocomplete="off">
	    </div>
	    <div class="layui-form-mid layui-word-aux">请务必填写学生姓名</div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">年龄</label>
	    <div class="layui-input-inline">
	      <input name="age" class="layui-input" type="text" value="${student.age}" autocomplete="off" lay-verify="required">
	    </div>
	  </div>
	  
	  <div class="layui-form-item" pane="">
	    <label class="layui-form-label">性别</label>
	    <c:if test="${student.gender=='男'}">
		    <div class="layui-input-block">
	    		<input name="gender" title="男" type="radio" checked="" value="男">
	    		<input name="gender" title="女" type="radio" value="女">
		    </div>
		 </c:if> 
		 <c:if test="${student.gender=='女'}">
		    <div class="layui-input-block">
	    		<input name="gender" title="男" type="radio" value="男">
	    		<input name="gender" title="女" type="radio" checked="" value="女">
		    </div>
		 </c:if> 
	    </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">出生日期</label>
	    <div class="layui-input-inline">
	    	<fmt:formatDate value="${student.birthday}" pattern="yyyy-MM-dd" var="birthday"/>
			<input name="birthday" id="birthdayId" class="layui-input" type="text" value="${birthday}" autocomplete="off" lay-verify="required" placeholder="yyyy-MM-dd">
	    </div>
	  </div> 
	  
	  <div class="layui-form-item">
		    <label class="layui-form-label">班级</label>
		    <div class="layui-input-inline">
			      <select id="classId" name="className">
			        <option>请选择班级</option>
			      </select>
    		</div>
    	</div>
	  
	  <div class="layui-form-item">
	    <button class="layui-btn" onclick="submitUpdate()">编辑</button>
	  </div>
	</form>
	
	<script src="${path}/static/jquery-1.11.3.js"></script>
	<script src="${path}/static/layui/layui.js"></script>
	<script src="${path}/static/mylayer.js"></script>
	<script src="${path}/static/util.js"></script>
	
	<script>
	layui.use(['form','laydate','layer'], function(){
		  var form = layui.form;
		  var layer = layui.layer;
		  var laydate = layui.laydate;
			  
		  laydate.render({
			 elem: '#birthdayId'
			 ,trigger: 'click'
		});
		  
	});
	
	$(function(){
		$.post(
			"${path}/classes/selectClass.action",
			function(jsonArray){
				console.log(jsonArray);
				$(jsonArray).each(function(){
					var html = "<option value='"+this.id+"'>"+this.name+"</option>";
					$("#classId").append(html);
				});
			},
			"json"
		);
	});
		
		function submitUpdate(){
			 $.ajax({
	    		  url:"${path}/student/updateById.action",
	    		  data:$("#update_form").serialize(),
	    		  dataType:"json",
	    		  type:"post",
	    		  success:function(jsonObj){
	    			  if(jsonObj.code == util.SUCCESS){
	    				  mylayer.successMsg(jsonObj.msg);
	    				  //当你在iframe页面关闭自身时
						  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						  setTimeout(function(){
								parent.layer.close(index); //再执行关闭 
								// 刷新父页面
								window.parent.location.reload();
						  },1000);
	    			  } else {
	    				  mylayer.errorMsg(jsonObj.msg);
	    			  }
	    		  }
			});
		}
	</script>
</body>
</html>